<template>
  <div :class="className" :style="{width: width, height: height}" />
</template>
<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons')
export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  methods: {
    // 初始化
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')
      this.setOptions()
    },
    setOptions() {
      this.chart.setOption(
        {
          tooltip: {},
          legend: {
            type: 'scroll',
            bottom: 10
          },
          series: [
            {
              name: 'flower',
              type: 'pie',
              roseType: 'radius',
              cursor: 'pointer',
              center: ['50%', '42%'],
              radius: [15, 95],
              data: [
                { value: 320, name: 'Industries' },
                { value: 240, name: 'Technology' },
                { value: 149, name: 'Forex' },
                { value: 100, name: 'Gold' },
                { value: 59, name: 'Forecasts' }
              ],
              animationEasing: 'cubicOut',
              animationDuration: 2000
            }
          ]
        }
      )
    }
  }
}
</script>
